Skip to content

feat(asyncpg): add capture_connection_cleanup option to silence pool cleanup spans#4373

Open
RiyaChaturvedi37 wants to merge 13 commits intoopen-telemetry:mainfrom
RiyaChaturvedi37:fix/asyncpg-silence-cleanup
Open

feat(asyncpg): add capture_connection_cleanup option to silence pool cleanup spans#4373
RiyaChaturvedi37 wants to merge 13 commits intoopen-telemetry:mainfrom
RiyaChaturvedi37:fix/asyncpg-silence-cleanup

Conversation

@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor

Closes #4264

Description

Adds a new capture_connection_cleanup option to AsyncPGInstrumentor
to allow silencing connection cleanup spans when using a pool.

When using a connection pool, asyncpg executes cleanup statements after
each invocation:

  • SELECT pg_advisory_unlock_all()
  • CLOSE ALL
  • UNLISTEN *
  • RESET ALL

These can pollute traces, especially for tasks that periodically query
the database. This option allows users to silence these spans.

Usage:

AsyncPGInstrumentor(capture_connection_cleanup=False).instrument()

The option defaults to True to maintain backward compatibility.

Type of change

  • New feature (non-breaking change which adds functionality)

@RiyaChaturvedi37 RiyaChaturvedi37 force-pushed the fix/asyncpg-silence-cleanup branch from 5547d9b to 73f9258 Compare March 28, 2026 08:49
@tammy-baylis-swi tammy-baylis-swi moved this to Ready for review in Python PR digest Mar 30, 2026
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Reviewed PRs that need fixes in Python PR digest Mar 30, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team March 30, 2026 18:11
@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Thank you for this @RiyaChaturvedi37 ! I have added some comments

@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

Note: The large diff (+2440/-2389) is due to Windows line ending (CRLF) differences in the existing file on my local machine. The actual code changes are minimal — only 3 files with the new feature, tests, and changelog entry. I apologize for the noise!

Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixes, lgtm! Just suggested a small docs update. The Maintainers will also have to review this.

@tammy-baylis-swi tammy-baylis-swi moved this from Reviewed PRs that need fixes to Ready for review in Python PR digest Mar 31, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team March 31, 2026 16:39
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Approved PRs in Python PR digest Mar 31, 2026
@RiyaChaturvedi37
Copy link
Copy Markdown
Contributor Author

Thank you for fixes, lgtm! Just suggested a small docs update. The Maintainers will also have to review this.

Done! Added the clarifying comment as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

asyncpg: ability to silence connection cleanup when using a pool

3 participants